package com.dcy.daily.skill.jvm.memoryAlloc.toolsOfJvm;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * VisualVM：多合一故障处理工具，Btrace插件测试用例,P170。
 *
 * @author duanchunyu
 * @version 1.0.0
 * @createTime 2021年06月10日 20:21:00
 */
public class VisualVM_BtraceUsage {

    public static int add(int a, int b) {
        return a + b;
    }

    public static void main(String[] args) throws IOException {
        VisualVM_BtraceUsage visualVM_btraceUsage = new VisualVM_BtraceUsage();
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        for (int i = 0; i < 10; i++) {
            bufferedReader.readLine();
            int a = (int) Math.round(Math.random() * 1000);
            int b = (int) Math.round(Math.random() * 1000);
            System.out.println(add(a, b));
        }
    }
}

/* BTrace Script Template *//*

import com.sun.btrace.annotations.*;
        import static com.sun.btrace.BTraceUtils.*;

@BTrace
public class TracingScript {
    @OnMethod(clazz = "com.dcy.daily.skill.jvm.memoryAlloc.toolsOfJvm.VisualVM_BtraceUsage", method = "add", location = @Location(Kind.RETURN))
    public static void func(@Self com.dcy.daily.skill.jvm.memoryAlloc.toolsOfJvm.VisualVM_BtraceUsage instance, int a, int b, @Return int result) {
        println("调用堆栈:");
        jstack();
        println(strcat("方法参数A:", str(a)));
        println(strcat("方法参数B:", str(b)));
        println(strcat("方法结果:", str(result)));
    }
}*/
